﻿namespace WpfApp.MesServices
{
    // DTO 类可以单独放在一个文件中
    public class StartRequestMessageDto
    {
        public string? Url { get; set; }
        public string? UserName { get; set; }
        public string? Password { get; set; }
        public string? Site { get; set; }
        public string? Resource { get; set; }
        public string? ModeProcessSfc { get; set; }
        public string? Operation { get; set; }
        public string? Activity { get; set; }
        public string? OperationRevision { get; set; }
        public string? User { get; set; }
        public string? Sfc { get; set; }
        public string? ProcessLot { get; set; }

        public bool Validate(out string errorMessage)
        {
            if (string.IsNullOrWhiteSpace(Url))
            {
                errorMessage = "MES API地址不能为空";
                return false;
            }

            if (string.IsNullOrWhiteSpace(UserName))
            {
                errorMessage = "用户名不能为空";
                return false;
            }

            if (string.IsNullOrWhiteSpace(Password))
            {
                errorMessage = "密码不能为空";
                return false;
            }

            if (string.IsNullOrWhiteSpace(Site))
            {
                errorMessage = "站点不能为空";
                return false;
            }

            if (string.IsNullOrWhiteSpace(Resource))
            {
                errorMessage = "设备资源资源号不能为空";
                return false;
            }

            if (string.IsNullOrWhiteSpace(Sfc))
            {
                errorMessage = "物料条码不能为空";
                return false;
            }

            // 验证URL格式
            if (!Uri.TryCreate(Url, UriKind.Absolute, out var uriResult) ||
                (uriResult.Scheme != Uri.UriSchemeHttp && uriResult.Scheme != Uri.UriSchemeHttps))
            {
                errorMessage = "MES API地址格式不正确";
                return false;
            }

            errorMessage = string.Empty;
            return true;
        }
    }
}